//
//  GxNetworkTool.swift
//  microblog
//
//  Created by 记忆不为 on 16/9/22.
//  Copyright © 2016年 记忆不为. All rights reserved.
//

import UIKit
import AFNetworking

enum GxNetworkMethod: String {
    case GET = "GET"
    case POST = "POST"
}

class GxNetworkTool: NSObject {

    static let shared: GxNetworkTool = GxNetworkTool()
    let afnManager: AFHTTPSessionManager
    fileprivate override init() {
        let URLString = "https://api.weibo.com/2/"
        let url = URL(string: URLString)
        afnManager = AFHTTPSessionManager(baseURL: url)
        afnManager.responseSerializer.acceptableContentTypes?.insert("text/plain")
    
        super.init()
        
    }
    func request(type: GxNetworkMethod,URLString: String,parameters: Any?,progress: ((Progress) -> Void)?, success: ((URLSessionDataTask, Any?) -> Void)?, failure: ((URLSessionDataTask?,Error) -> Void)?) -> Void{
        
        switch type {
        case .GET:
            afnManager.get(URLString, parameters: parameters, progress: progress, success: success, failure: failure)
        case .POST:
            afnManager.post(URLString, parameters: parameters, progress: progress, success: success, failure: failure)
            
        }
    }
    
}
